// 省市区，三级联动
// 省
$.getJSON("/intfc/config/json/localProvince.jhtml", function (date) {
    //  有默认值
    var idP = $(".province").val();
    if (idP != "") {
        $(".province").html("<option value=''>" + "选择省" + "</option>");
        $(".city").attr("disabled", false);
        $.getJSON("/intfc/config/json/localChildren.jhtml?id=" + idP, function (date) {
            var idC = $(".city").val();
            if (idC != "") {
                $(".district").attr("disabled", false);
                $.getJSON("/intfc/config/json/localChildren.jhtml?id=" + idC, function (date) {
                    var idD = $(".district").val();
                    date.forEach(function (item) {
                        if (item.parentId == idC) {
                            //        判断是否为被选项
                            if (item.parentId == idD) {
                                var sOption = "<option value='" + com.project.common.web.utils.id + "' selected='selected'>" + item.name + "</option>";
                            } else {
                                var sOption = "<option value='" + com.project.common.web.utils.id + "'>" + item.name + "</option>";
                            }
                            $(".district").append(sOption);
                        }
                    });
                });
            }
            date.forEach(function (item) {
                if (item.parentId == idP) {
                    //        判断是否为被选项
                    if (item.parentId == idC) {
                        var sOption = "<option value='" + com.project.common.web.utils.id + "' selected='selected'>" + item.name + "</option>";
                    } else {
                        var sOption = "<option value='" + com.project.common.web.utils.id + "'>" + item.name + "</option>";
                    }
                    $(".city").append(sOption);
                }
            });
        });
    }
    date.forEach(function (item) {
//        判断是否为被选项
        if (com.project.common.web.utils.id == idP) {
            var pOption = "<option value='" + com.project.common.web.utils.id + "' selected='selected'>" + item.name + "</option>";
        } else {
            var pOption = "<option value='" + com.project.common.web.utils.id + "'>" + item.name + "</option>";
        }
        $(".province").append(pOption);
    });
});

// 市
$(".province").change(function () {
    $(".city").attr("disabled", false);
    $(".city").children().remove();
    $(".district").children().remove();
    var idP = $(".province").val();
    if (idP == "") {
        $(".city").html("<option value=''>" + "选择市" + "</option>");
        $(".city").trigger("change");
    } else {
        $.getJSON("/intfc/config/json/localChildren.jhtml?id=" + idP, function (date) {
            var pId = $(".province").val();
            date.forEach(function (item) {
                if (item.parentId == pId) {
                    var sOption = "<option value='" + com.project.common.web.utils.id + "'>" + item.name + "</option>";
                    $(".city").append(sOption);
                }
            });
            $(".city").trigger("change");
        });
    }
});

// 区
$(".city").change(function () {
    $(".district").attr("disabled", false);
    $(".district").children().remove();
    var idC = $(".city").val();
    if (idC == "") {
        $(".district").html("<option value=''>" + "选择区/县" + "</option>");
    } else {
        $.getJSON("/intfc/config/json/localChildren.jhtml?id=" + idC, function (date) {
            var pId = $(".city").val();
            date.forEach(function (item) {
                if (item.parentId == pId) {
                    var sOption = "<option value='" + com.project.common.web.utils.id + "'>" + item.name + "</option>";
                    $(".district").append(sOption);
                }
            });
        });
    }
});